function TreeNode(x) {
  this.val = x;
  this.left = null;
  this.right = null;
} 
function Convert(pRootOfTree)
{
  // write code here
  if (!pRootOfTree) return null
  let pre = null
  let head = null
  function dfs (root) {
      if (!root) return
      dfs(root.left)
      if (!pre) {
          head = root
      } else {
          pre.right = root
      }
      root.left = pre
      pre = root
      dfs(root.right)
  }
  dfs(pRootOfTree)
  /*
  let root = res.shift()
  let node = root
  while (node && res.length) {
      let afterNode = res.shift()
      node.right = afterNode
      afterNode.left = node
  }
  root.left = node
  node.right = root
  */
  return head   
}
module.exports = {
  Convert : Convert
};